﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GeneracListConsoleApp
{
    public class GenericList<T>
    {
        private Node<T> head;
        private Node<T> tail;

        public GenericList()
        {
            head = tail = null;
        }

        public Node<T> Head { get => head; }

        public Node<T> Tail { get => tail; }

        public T Max { get; set; }

        public T Min { get; set; }

        public double Sum { get; set; }

        public void Add(T t)
        {
            Node<T> node = new Node<T>(t);
            if (tail == null)
            {
                head = tail = node;
            }
            else
            {
                tail.Next = node;
                tail = node;
            }
        }

        public IEnumerable<T> ForEachGenericList(Action<Node<T>> action)
        {
            Node<T> current = Head;
            while (current != null)
            {
                yield return current.Data;
                Console.WriteLine("当前元素："+current.Data.ToString());//打印

                action(current);

                current = current.Next;
            }
        }

    }
}
